#include "dsi_reciver_chip.h"

void lcdInitial(void)
{
	MIPI_WR(0x15, 0xF0, 0xC3);
	MIPI_WR(0x15, 0xF0, 0x96);
	MIPI_WR(0x15, 0xED, 0xC3);
	MIPI_WR(0x39, 0xE4, 0x40, 0x03);
		
	MIPI_WR(0x15, 0xE7,0x80);
	MIPI_WR(0x39, 0xC3,0x33,0x01,0x24,0x02);

	MIPI_WR(0x29, 0xE5,0x9F,0xF5,0x90,0x11,0x66,0x25,0x10,0x22,0x22,0x22,0x22,0x22);

	MIPI_WR(0x39, 0xEC,0x00,0x55,0x00,0x00,0x00,0x49,0x22);
	MIPI_WR(0x39, 0xC1,0x77,0x05,0xAF,0x15);  // Power Control

	//MIPI_WR(0x15, 0x36,0x0C);  // FW: 0C, BW: 18 ; #MX, MY: 18
	MIPI_WR(0x15, 0x36,0x00);  // FW: 0C, BW: 18 ; #MX, MY: 18
	MIPI_WR(0x15, 0x3A,0x07);  // #16M Color
	MIPI_WR(0x15, 0xC5,0x47);  // #VCOM     
		
	MIPI_WR(0x39, 0xE0,0xF0,0x0E,0x15,0x0A,0x0A,0x06,0x3B,0x43,0x52,0x08,0x15,0x15,0x32,0x36);  //#Gamma
	MIPI_WR(0x39, 0xE1,0xF0,0x0F,0x15,0x0A,0x0A,0x06,0x3C,0x43,0x52,0x09,0x15,0x15,0x32,0x36);  //#Gamma
																
										
	MIPI_WR(0x15, 0xB2,0x10);	  //	#FW: 10, BW: 11		#Gate Scan Control
	MIPI_WR(0x15, 0xB3,0x01);       // #Inversion normal
	MIPI_WR(0x39, 0xB6,0xC7,0x31);  // #400*400
	MIPI_WR(0x39, 0xA5,0x00,0x00,0x00,0x00,0x20,0x16,0x2A,0x8A,0x02);			
	MIPI_WR(0x39, 0xA6,0x00,0x00,0x00,0x00,0x00,0x13,0x2A,0x8A,0x02);
	MIPI_WR(0x39, 0xBA,0x19,0x0A,0x23,0x00,0x22,0x02,0x00);	    //	#GIP Mode
		
	MIPI_WR(0x39, 0xBB,0x00,0x22,0x00,0x2B,0x82,0x87,0x18,0x00);      // #GIP Control(normal)	
	MIPI_WR(0x39, 0xBC,0x00,0x30,0x00,0x2C,0x82,0x87,0x18,0x00);      // #GIP Control(idle)	
		
	MIPI_WR(0x39, 0xBD,0x16,0x61,0xFF,0xFF,0x54,0x45,0xFF,0xFF,0x32,0xFF,0x0F);  // #GIP Route	
	MIPI_WR(0x15, 0xF0,0x3C);
	MIPI_WR(0x15, 0xF0,0x69);
		
	MIPI_WR(0x05, 0x11, 0x00);
	HAL_Delay (120);
	MIPI_WR(0x05, 0x29, 0x00);
	//MIPI_WR(0x05, 0x21, 0x00);     
	HAL_Delay (120);
	MIPI_WR(0x15, 0x35, 0x00);
}

void bist(void){
    MIPI_WR(0x15, 0xB0, 0xA5);
    MIPI_WR(0x39, 0xCC, 0x40, 0x00, 0x3F, 0x01, 0x14, 0x14, 0x20, 0x20, 0x03);
}